package com.eedi.framework.file.service;

import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.file.controller.sys.vo.FilePresignedUrlRespVO;
import com.eedi.framework.file.core.client.FileClient;
import com.eedi.framework.file.core.client.s3.FilePresignedUrlRespDTO;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 文件 Service 实现类
 *
 * @author 芋道源码
 */
@Service
public class FileServiceImpl implements FileService {

    @Resource
    private FileClient fileClientPublic;

    @Resource
    private FileClient fileClientPrivate;


    @SneakyThrows
    @Override
    public FilePresignedUrlRespVO getFilePresignedUrlForPulbic(String path)  {
        FilePresignedUrlRespDTO presignedObjectUrl = fileClientPublic.getPresignedObjectUrl(path);
        return BeanUtils.toBean(presignedObjectUrl, FilePresignedUrlRespVO.class);
    }

    @SneakyThrows
    @Override
    public FilePresignedUrlRespVO getFilePresignedUrl(String path)  {
        FilePresignedUrlRespDTO presignedObjectUrl = fileClientPrivate.getPresignedObjectUrl(path);
        return BeanUtils.toBean(presignedObjectUrl, FilePresignedUrlRespVO.class);
    }

    @SneakyThrows
    @Override
    public String getPresignedObjectDownloadUrl(String path){
        return  fileClientPrivate.getPresignedObjectDownloadUrl(path);
    }

}
